import React, { Component } from "react";
/* 
组件卸载时
componentWillUnmount
*/
class Demo extends Component {
  render() {
    return <h1>Demo组件</h1>;
  }
  componentDidMount(){
   this.timeId = setInterval(() => {
      console.log(1)
    }, 1000);
  }
  componentWillUnmount() {

    //清除订阅 清定时器...
    console.log("Demo组件卸载");
    clearInterval(this.timeId)
  }
}
class App extends Component {
  state = {
    show: true,
  };
  handleClick = () => {
    this.setState({
      show: false,
    });
  };
  render() {
    return (
      <div>
        {this.state.show? <Demo></Demo> : ""}
        <button onClick={this.handleClick}>卸载组件</button>
      </div>
    );
  }
}

export default App;
